import {
  clearAllStorage,
  loadDataFromCookie,
  saveDataToCookie,
} from './StorageUtil'
import { isNotNullAndNotUndefined } from './TypeUtils'

const login_flag = 'loginFlag'

export function saveLoginResult(loginFlag) {
  if (isNotNullAndNotUndefined(loginFlag)) {
    //@ts-ignore
    saveDataToCookie(login_flag, loginFlag)
    return true
  }
  return false
}

export function getLoginFlag() {
  return loadDataFromCookie(login_flag)
}

export function isLogin() {
  return !!getLoginFlag()
}

export function clearLoginData() {
  clearAllStorage()
}
